// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   EncoderView.java

package jones.gui;

import java.awt.*;
import java.util.Observable;
import java.util.Observer;
import javax.swing.*;
import jones.SimpleRobotInterface;

public class EncoderView extends JPanel
    implements Observer
{

    private JProgressBar topLeftSpeedMeter = null;
    private JProgressBar topRightSpeedMeter = null;
    private JProgressBar bottomLeftSpeedMeter = null;
    private JProgressBar bottomRightSpeedMeter = null;

    public EncoderView()
    {
        topLeftSpeedMeter = new JProgressBar(1, 0, 255);
        topRightSpeedMeter = new JProgressBar(1, 0, 255);
        bottomLeftSpeedMeter = new JProgressBar(1, -255, 0);
        bottomRightSpeedMeter = new JProgressBar(1, -255, 0);
        JPanel labelPanel = new JPanel(((java.awt.LayoutManager) (new BorderLayout())));
        JLabel maxLabel = new JLabel(Integer.toString(255));
        maxLabel.setHorizontalAlignment(4);
        maxLabel.setVerticalAlignment(1);
        labelPanel.add(((java.awt.Component) (maxLabel)), "North");
        JLabel zeroLabel = new JLabel(Integer.toString(0));
        zeroLabel.setHorizontalAlignment(4);
        zeroLabel.setVerticalAlignment(0);
        labelPanel.add(((java.awt.Component) (zeroLabel)), "Center");
        JLabel minLabel = new JLabel(Integer.toString(-255));
        minLabel.setHorizontalAlignment(4);
        minLabel.setVerticalAlignment(3);
        labelPanel.add(((java.awt.Component) (minLabel)), "South");
        add(((java.awt.Component) (labelPanel)));
        JPanel leftSpeedMeter = new JPanel(((java.awt.LayoutManager) (new BorderLayout())));
        leftSpeedMeter.add(((java.awt.Component) (topLeftSpeedMeter)), "North");
        leftSpeedMeter.add(((java.awt.Component) (bottomLeftSpeedMeter)), "South");
        add(((java.awt.Component) (leftSpeedMeter)));
        JPanel rightSpeedMeter = new JPanel(((java.awt.LayoutManager) (new BorderLayout())));
        rightSpeedMeter.add(((java.awt.Component) (topRightSpeedMeter)), "North");
        rightSpeedMeter.add(((java.awt.Component) (bottomRightSpeedMeter)), "South");
        add(((java.awt.Component) (rightSpeedMeter)));
        topLeftSpeedMeter.setPreferredSize(new Dimension(15, 20));
        topLeftSpeedMeter.setForeground(Color.green);
        bottomLeftSpeedMeter.setPreferredSize(new Dimension(15, 20));
        bottomLeftSpeedMeter.setForeground(topLeftSpeedMeter.getBackground());
        bottomLeftSpeedMeter.setBackground(Color.green);
        bottomLeftSpeedMeter.setValue(0);
        topRightSpeedMeter.setPreferredSize(new Dimension(15, 20));
        topRightSpeedMeter.setForeground(Color.green);
        bottomRightSpeedMeter.setPreferredSize(new Dimension(15, 20));
        bottomRightSpeedMeter.setForeground(topRightSpeedMeter.getBackground());
        bottomRightSpeedMeter.setBackground(Color.green);
        bottomRightSpeedMeter.setValue(0);
    }

    public void update(Observable obs, Object obj)
    {
        final SimpleRobotInterface robot = (SimpleRobotInterface)obs;
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                if (robot.getLeftWheelSpeed() > 0)
                {
                    topLeftSpeedMeter.setValue(robot.getLeftWheelSpeed());
                    bottomLeftSpeedMeter.setValue(0);
                } else
                {
                    topLeftSpeedMeter.setValue(0);
                    bottomLeftSpeedMeter.setValue(robot.getLeftWheelSpeed());
                }
                if (robot.getRightWheelSpeed() > 0)
                {
                    topRightSpeedMeter.setValue(robot.getRightWheelSpeed());
                    bottomRightSpeedMeter.setValue(0);
                } else
                {
                    topRightSpeedMeter.setValue(0);
                    bottomRightSpeedMeter.setValue(robot.getRightWheelSpeed());
                }
            }

        }
);
        repaint();
    }




}
